import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Selenium {
    void test() throws InterruptedException {
        //使用驱动打开浏览器
        //启动谷歌浏览器
        WebDriverManager.chromedriver().setup();
        //增加浏览器配置，允许访问所有链接
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        //将配置添加到驱动中
        WebDriver driver = new ChromeDriver(options);
        //输入网址
        //输入百度网址
        driver.get("https://www.baidu.com");
        Thread.sleep(3000);
        //找到输入框，输入CSDN
        driver.findElement(By.cssSelector("#kw")).sendKeys("CSDN");
        Thread.sleep(3000);
        //找到百度一下并点击
        driver.findElement(By.cssSelector("#su")).click();
        Thread.sleep(3000);
        //关闭浏览器
        driver.quit();
    }
}
